public class MyQueue {
    static class Node {
        public int val;
        public Node next;
        public Node (int val) {
            this.val = val;
        }
    }
    public Node head;
    public Node last;
    public int usedSize;
    //入队
    public void offer (int data) {
        Node node = new Node(data);
        if (head == null) {
            head = node;
            last = node;
        } else {
            last.next = node;
            last = node;
        }
        usedSize++;
    }
    public int poll () {
        if (empty()) {
            return -1;
        }
        int ret = this.head.val;
        this.head = this.head.next;
        if (this.head == null) {
            this.last = null; // 表明只有一个节点
        }
        usedSize--;
        return ret;
    }
    public boolean empty () {
        return head == null;
    }
    public int getUsedSize () {
        return usedSize;
    }
}
